package com.estate.business.impl;

import java.util.HashMap;
import java.util.List;

import com.estate.business.LibraryService;
import com.estate.dao.DocumentDao;
import com.estate.dao.EfileDao;
import com.estate.dao.FileDeleteDao;
import com.estate.dao.LendDocumentDao;
import com.estate.dao.LibraryDao;
import com.estate.vo.Vo;
import com.estate.vo.impl.DocumentVo;
import com.estate.vo.impl.EfileVo;
import com.estate.vo.impl.FileDeleteVo;
import com.estate.vo.impl.LendDocumentVo;
import com.estate.vo.impl.LibraryVo;

public class LibraryServiceImpl implements LibraryService {
	
	private LibraryDao libraryDao;
	private DocumentDao documentDao;
	private EfileDao efileDao;
	private FileDeleteDao fileDeleteDao; 
	private LendDocumentDao lendDocumentDao;
	
	public void addLibrary(LibraryVo vo) {
		// TODO Auto-generated method stub
		libraryDao.addVo(vo);
		
	}

	public List<Vo> findAllLibrary() {
		// TODO Auto-generated method stub
		return libraryDao.findAll();
	}

	public void deleteByPK(int id) {
		// TODO Auto-generated method stub
		Vo vo=libraryDao.findByPK(id);
		List<DocumentVo> documentList=documentDao.findByLibraryId(id);
		for(int i=0;i<documentList.size();i++){
			List<EfileVo> voList=efileDao.findByDocumentId(documentList.get(i).getId());
			for(int j=0;j<voList.size();j++){
				FileDeleteVo deleteVo=new FileDeleteVo();
				deleteVo.setFilePath(voList.get(j).getFilePath());
				fileDeleteDao.addVo(deleteVo);
				efileDao.deleteVo(voList.get(j));
			}
			List<LendDocumentVo> lendVoList=lendDocumentDao.findByDocumentId(documentList.get(i).getId());
			for(int j=0;j<lendVoList.size();j++){
				lendDocumentDao.deleteVo(lendVoList.get(j));
			}
			documentDao.deleteVo(documentList.get(i));
		}
		libraryDao.deleteVo(vo);
	}


	public void setLibraryDao(LibraryDao libraryDao) {
		this.libraryDao = libraryDao;
	}

	public LibraryDao getLibraryDao() {
		return libraryDao;
	}

	public Vo findByPK(int id) {
		// TODO Auto-generated method stub
		return libraryDao.findByPK(id);
	}

	public void update(Vo vo) {
		// TODO Auto-generated method stub
		libraryDao.updateVo(vo);
	}

	public HashMap<Integer, String> findAllIdAndName() {
		// TODO Auto-generated method stub
		List<LibraryVo> voList=libraryDao.findAllLibrary();
		HashMap<Integer,String> map=new HashMap<Integer,String>();
		for(int i=0;i<voList.size();i++){
			map.put(voList.get(i).getId(), voList.get(i).getLibraryName());
			System.out.println(voList.get(i).getId()+"      "+voList.get(i).getLibraryName());
		}
		return map;
	}

	public void setDocumentDao(DocumentDao documentDao) {
		this.documentDao = documentDao;
	}

	public DocumentDao getDocumentDao() {
		return documentDao;
	}

	public void setEfileDao(EfileDao efileDao) {
		this.efileDao = efileDao;
	}

	public EfileDao getEfileDao() {
		return efileDao;
	}

	public void setFileDeleteDao(FileDeleteDao fileDeleteDao) {
		this.fileDeleteDao = fileDeleteDao;
	}

	public FileDeleteDao getFileDeleteDao() {
		return fileDeleteDao;
	}

	public void setLendDocumentDao(LendDocumentDao lendDocumentDao) {
		this.lendDocumentDao = lendDocumentDao;
	}

	public LendDocumentDao getLendDocumentDao() {
		return lendDocumentDao;
	}

	
}
